package nine.test_9_26;

import java.util.Scanner;

public class TestMain2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        boolean bs = false;
        int cur = 0;
        int max = -1;
        int count = 0;
        for (int i = 1; i < n; i++) {

            if(i - cur == k) {
                max = Math.max(count,max);
                if(arr[cur] % arr[cur - 1] == 0) {
                    int min = Math.min(arr[cur - 1],arr[cur]);
                    count -= min;
                }
                cur++;
            }
            if(arr[i] % arr[i - 1] == 0 ) {
                int min = Math.min(arr[i - 1],arr[i]);
                count += min;
                bs = true;
            } else {
                cur = i;
            }
        }
        max = Math.max(count,max);
        if(bs) {
            System.out.println(max);
        } else {
            System.out.println(-1);
        }
    }
}
